package com.stox.services.watchlist.repository.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import com.stox.services.core.repository.AbstractCachingFileRepository;
import com.stox.services.watchlist.repository.WatchlistEntryRepository;
import com.stox.shared.model.WatchlistEntry;

@Component
public class WatchlistEntiryFileRepository extends
		AbstractCachingFileRepository<WatchlistEntry> implements WatchlistEntryRepository {
	
	public WatchlistEntiryFileRepository() {
		super("watchlistEntry");
	}
	
	@Override
	public List<WatchlistEntry> findByWatchlistId(Long watchlistId) {
		List<WatchlistEntry> result = new ArrayList<>();
		for(WatchlistEntry watchlistEntry : findAll()){
			if(watchlistId.equals(watchlistEntry.getWatchlistId())){
				result.add(watchlistEntry);
			}
		}
		return result;
	}

	@Override
	public WatchlistEntry deserialize(String text) {
		return new WatchlistEntry(text);
	}

	@Override
	public String serialize(WatchlistEntry entity) {
		return entity.toString();
	}

	

}
